﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfAGVSystem.DBModel;

namespace WpfAGVSystem.Model
{
    public class TaskTypeMgrClass
    {
        public TaskType_Entity TaskType_EF { get; set; }


        public List<object> ForntActionItems
        {
            get
            {
                string[] lists = string.IsNullOrEmpty(TaskType_EF.ForntAction) ? new string[0] : TaskType_EF.ForntAction.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        items.Add(result);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.ForntAction = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{','}");
                    }
                }
                TaskType_EF.ForntAction = stringBuilder.ToString();
            }
        }

        public List<object> TargetActionItems
        {
            get
            {
                string[] lists = string.IsNullOrEmpty(TaskType_EF.TargetAction) ? new string[0] : TaskType_EF.TargetAction.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); 
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        items.Add(result);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TargetAction = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{','}");
                    }
                }
                TaskType_EF.TargetAction = stringBuilder.ToString();
            }
        }

        public List<object> RearActionItems
        {
            get
            {
                string[] lists = string.IsNullOrEmpty(TaskType_EF.RearAction) ? new string[0] : TaskType_EF.RearAction.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        items.Add(result);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.RearAction = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{','}");
                    }
                }
                TaskType_EF.RearAction = stringBuilder.ToString();
            }
        }

        public List<object> TaskPreTaskItems
        {
            get
            {
              
                string[] lists = string.IsNullOrEmpty(TaskType_EF.TaskPreTask) ? new string[0] : TaskType_EF.TaskPreTask.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        items.Add(result);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TaskPreTask = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{','}");
                    }
                }
                TaskType_EF.TaskPreTask = stringBuilder.ToString();
            }
        }

        public List<object> TaskStartExcuteItems
        {
            get
            {
                string[] lists = string.IsNullOrEmpty(TaskType_EF.TaskStartExcute) ? new string[0] : TaskType_EF.TaskStartExcute.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
              
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        items.Add(result);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TaskStartExcute = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{','}");
                    }
                }
                TaskType_EF.TaskStartExcute = stringBuilder.ToString();

            }
        }

        public List<object> TaskStartFinishItems
        {
            get
            {
                string[] lists = string.IsNullOrEmpty(TaskType_EF.TaskStartFinish) ? new string[0] : TaskType_EF.TaskStartFinish.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
               
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        items.Add(result);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TaskStartFinish = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{','}");
                    }
                }
                TaskType_EF.TaskStartFinish = stringBuilder.ToString();
            }
        }
    }
}
